using UnityEngine;
using System;
using UnityEngine.Events;
using UnityEngine.AI;
using System.Collections.Generic;


/// <summary>
/// 简易AI状态机
/// </summary>
public abstract class FSMAI<T>: MonoBehaviour where T:Enum
{
    public FSMAINodeBase<T> ActiveNode{protected set;get;}
    
    public T Status {protected set; get; }
    protected NavMeshAgent navigator;



    private void Update()
    {
        if(ActiveNode!=null)
            RunNode();
    }



    public void ChangeStatus(T value)
    {
        LeaveStatus();
        Status = value;
        EnterStatus();
    }



    private void RunNode()
    {
        var result = ActiveNode.RunningNode();

        if(result)
            ChangeStatus(ActiveNode.NextState);
    }



    protected abstract void LeaveStatus();
    protected abstract void EnterStatus();
}
